<?php
//by ralvear 2013-08-09

class Vista
{
	private $_controlador;
	private $_js;

	public function __construct(Peticion $objPeticion){
		$this->_controlador = $objPeticion->obtenerControlador();
		$this->_js = array();
	}

	public function render( $vista , $item = false){
		//menu componente
		$arrayMenu = array( 
			array("codigo" => "1", "padre" => "0", "nombre" => "General", "control" => BASE_URL."", "icono" => "icono", "titulo" => "titulo", "id" => ""),//modulo #1 {crud usuarios}
				array("codigo" => "2", "padre" => "1", "nombre" => "Usuarios - usu", "control" => BASE_URL . "usuario/", "icono" => "icono", "titulo" => "titulo", "id" => "usuario"),

			array("codigo" => "11", "padre" => "0", "nombre" => "KPIS de Cartera", "control" => "", "icono" => "icono", "titulo" => "titulo", "id" => ""),//grupo #1 { carlos arboleda, juan carlos , ramiro alvear}
				array("codigo" => "12", "padre" => "11", "nombre" => "Total Ventas Credito ", "control" => BASE_URL."ventascredito/", "icono" => "icono", "titulo" => "Total Ventas Credito", "id" => ""),
				array("codigo" => "13", "padre" => "11", "nombre" => "Cartera Cliente ", "control" => BASE_URL."carteracliente/", "icono" => "icono", "titulo" => "Cartera Cliente", "id" => ""),
				array("codigo" => "14", "padre" => "11", "nombre" => "Cartera Producto ", "control" => BASE_URL."carteraproducto/", "icono" => "icono", "titulo" => "Cartera Producto", "id" => ""),
				array("codigo" => "15", "padre" => "11", "nombre" => "Cartera Almacen ", "control" => BASE_URL."carteraalmacen/", "icono" => "icono", "titulo" => "Cartera Almacen", "id" => ""),
				array("codigo" => "16", "padre" => "11", "nombre" => "Nivel Cartera ", "control" => BASE_URL."nivelcartera/", "icono" => "icono", "titulo" => "Nivel Cartera", "id" => ""),
				array("codigo" => "17", "padre" => "11", "nombre" => "Historico de Abonos por Mes ", "control" => BASE_URL."historicoabonosxmes/", "icono" => "icono", "titulo" => "Historico de Abonos por Mes", "id" => ""),
				array("codigo" => "18", "padre" => "11", "nombre" => "Historico de Cartera Mensual ", "control" => BASE_URL."historicocarteraxmes/", "icono" => "icono", "titulo" => "Historico de Cartera por Mes", "id" => ""),
				array("codigo" => "19", "padre" => "11", "nombre" => "Top 10 Cartera ", "control" => BASE_URL."top10cartera/", "icono" => "icono", "titulo" => "Top 10 de clientes, productos, meses y almacén con más cartera", "id" => ""),
				array("codigo" => "24", "padre" => "11", "nombre" => "Reporte de cartera vencida", "control" => BASE_URL."carteravencida/", "icono" => "icono", "titulo" => "Cartera vencida", "id" => ""),
	
			//grupo #2 { diana, yesid, julian, diana }
			array("codigo" => "25", "padre" => "0", "nombre" => "KPIS de Compras", "control" => "controlador", "icono" => "icono", "titulo" => "titulo", "id" => ""),
				array("codigo" => "26", "padre" => "25", "nombre" => "Compras por Proveedor ", "control" => BASE_URL."comprasproveedor/", "icono" => "icono", "titulo" => "Compras Proveedor", "id" => ""),
				array("codigo" => "27", "padre" => "25", "nombre" => "Compras por Producto", "control" => BASE_URL."comprasproducto/", "icono" => "icono", "titulo" => "Compras Producto", "id" => ""),
				array("codigo" => "28", "padre" => "25", "nombre" => "Compras por Almacen", "control" => BASE_URL."comprasalmacen/", "icono" => "icono", "titulo" => "Compras Almacen", "id" => ""),
				array("codigo" => "29", "padre" => "25", "nombre" => "Compras por Tipo Iva", "control" => BASE_URL."comprastipoiva/", "icono" => "icono", "titulo" => "Compras por Tipo Iva", "id" => ""),
				array("codigo" => "26", "padre" => "25", "nombre" => "Compras por Linea y Dpto", "control" => BASE_URL."compraslineadpto/", "icono" => "icono", "titulo" => "Compras por Linea y Dpto", "id" => ""),
				array("codigo" => "27", "padre" => "25", "nombre" => "Historico de Compras por Mes", "control" => BASE_URL."comprashistoricoxmes/", "icono" => "icono", "titulo" => "Historico de Compras por Mes", "id" => ""),
				array("codigo" => "28", "padre" => "25", "nombre" => "Compras media por Proveedor", "control" => BASE_URL."comprasmediaxproveedor/", "icono" => "icono", "titulo" => "Compras media por Proveedor", "id" => ""),
				array("codigo" => "29", "padre" => "25", "nombre" => "Top 10 de Compras", "control" => BASE_URL."comprastop10/", "icono" => "icono", "titulo" => "Top 10 de Compras", "id" => ""),
				array("codigo" => "30", "padre" => "25", "nombre" => "Variacion de las Compras", "control" => BASE_URL."comprasvariacion/", "icono" => "icono", "titulo" => "Variacion de las Compras", "id" => ""),


			//grupo #3 { }
			array("codigo" => "31", "padre" => "0", "nombre" => "KPIS de Facturacion", "control" => "controlador", "icono" => "icono", "titulo" => "titulo", "id" => ""),
				array("codigo" => "32", "padre" => "31", "nombre" => "Ventas por Medio de Pago ", "control" => BASE_URL."ventasmediopago/", "icono" => "icono", "titulo" => "Ventas por Medio de Pago", "id" => ""),
				array("codigo" => "33", "padre" => "31", "nombre" => "Ventas por Almacen Especifico", "control" => BASE_URL."ventasalmacen/", "icono" => "icono", "titulo" => "Ventas por Almacen Especificos", "id" => ""),
				array("codigo" => "34", "padre" => "31", "nombre" => "Ventas por Empleado Especifico", "control" => BASE_URL."ventasempleado/", "icono" => "icono", "titulo" => "Ventas por Empleado Especifico", "id" => ""),
				array("codigo" => "35", "padre" => "31", "nombre" => "Ventas por Producto Especifico", "control" => BASE_URL."ventasproducto/", "icono" => "icono", "titulo" => "Ventas por Producto Especifico", "id" => ""),
				array("codigo" => "36", "padre" => "31", "nombre" => "Ventas por Linea y Dpto", "control" => BASE_URL."ventaslineas/", "icono" => "icono", "titulo" => "Ventas por Linea y Dpto", "id" => ""),
				array("codigo" => "37", "padre" => "31", "nombre" => "Ventas para Cliente Especifico", "control" => BASE_URL."ventascliente/", "icono" => "icono", "titulo" => "Ventas para Cliente Especifico", "id" => ""),
				array("codigo" => "38", "padre" => "31", "nombre" => "Variacion de las ventas", "control" => BASE_URL."ventasvariacion/", "icono" => "icono", "titulo" => "Variacion de las ventas", "id" => "")
		);
		
		$_arrRuta = array(
			"jquery" => BASE_URL . "lib/jquery/jquery-1.8.3.js",
			"jqueryui" => BASE_URL . "lib/jqueryui/jquery-ui-1.9.2.custom.js",
			"cssui" => BASE_URL . "vista/tema/" . TEMA_DEFECTO . "/jquery.ui.all.css",
			"cssdefecto" => BASE_URL . "vista/bin/css/defecto.css",
			"img" => BASE_URL . "img/",
			"jsvdialogo" => BASE_URL . "vista/bin/js/vdialogo.js",
			"utilidades" => BASE_URL . "vista/bin/js/utilidades.js",
			"jstree" => BASE_URL . "lib/jstree/jquery.jstree.js",
			"jstree_imp" => BASE_URL . "vista/bin/js/jstree_imp.js",
			"highcharts" => BASE_URL . "lib/highcharts/js/highcharts.js",
			"highcharts_theme" => BASE_URL . "lib/highcharts/js/themes/grid.js",
			"exporting" => BASE_URL . "lib/highcharts/js/modules/exporting.js",
			"bootstrapcss" => BASE_URL . "lib/bootstrap3/css/bootstrap.min.css",
			"bootstrapcss-res" => BASE_URL . "lib/bootstrap/css/bootstrap-responsive.min.css",
			"bootstrap" => BASE_URL . "lib/bootstrap3/js/bootstrap.min.js",
			"datepickercss" => BASE_URL . "lib/datepicker/css/datepicker.css",			
			"datepicker" => BASE_URL . "lib/datepicker/js/bootstrap-datepicker.js"
		);
		
		//var_dump($_arrRuta);exit;

		$rutaContenido = RUTA . "vista" . BNVA . $this->_controlador . BNVA . $vista . ".phtml";

		if( is_readable( $rutaContenido ) ){
			include_once ( RUTA . "vista" . BNVA . "bin" . BNVA . "cabecera.php");
			include_once ( $rutaContenido );
			include_once ( RUTA . "vista" . BNVA . "bin" . BNVA . "piedepagina.php");
		}else{
			throw new Exception ("Error: Vista no encontrado...");
		}

	}

	public function renderSinCabecera( $vista , $item){
		$rutaContenido = RUTA . "vista" . BNVA . $this->_controlador . BNVA . $vista . ".phtml";
		if( is_readable( $rutaContenido ) ){
			$datos_vista = $item;
			include_once ( $rutaContenido );
		}else{
			throw new Exception ("Error: Vista no encontrado...");
		}

	}

	public function asignartJs ( array $js ){

		if( is_array( $js ) && count( $js ) ){

			for( $i = 0; $i < count( $js ); $i++ ){
				$this->_js[] = BASE_URL . "vista/" . $this->_controlador . "/js/" . $js[$i] . ".js";
			}

		}else{
			throw new Exception("Error: Javascript no encontrado...");
		}

	}

}
?>